#include <vector>
#include <string>

#include "Binding/BoundScope.hpp"

bool BoundScope::TryDeclare(SharedVariableSymbol variable)
{
    auto it = this->Variables.find(variable->GetName());
    if (it != this->Variables.end())
        return false;

    this->Variables.insert(std::pair<std::string, SharedVariableSymbol>(variable->GetName(), variable));
    return true;
}
SharedVariableSymbol BoundScope::TryLookup(std::string name)
{
    auto it = this->Variables.find(name);
    if (it != this->Variables.end())
        return it->second;

    if (this->Parent == nullptr)
        return nullptr;
    return this->Parent->TryLookup(name);
}

std::vector<SharedVariableSymbol> BoundScope::GetDeclaredVariables()
{
    std::vector<SharedVariableSymbol> values;
    for (auto v : this->Variables)
    {
        values.push_back(v.second);
    }
    return values;
}